<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Gain</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Gain</p>
    	
       <p class="linkListHeader">Fields</p>
       <p class="linkList">
           
    <a href="gain_field_audio.html" title="The audio input is where incoming signals should be patched, however you do not need 
 to patch directly to this input because patching to the Gain itself will accomplish
 the same thing.">audio</a><br/>
    
    <a href="gain_field_gain.html" title="The gain input controls the value of this Gain. It will be interpreted as being in dB. 
 0 dB means that the incoming signal will not be changed, positive dB increases the 
 amplitude of the signal, and negative dB decreases it. You can effectively silence 
 the incoming signal by setting the gain to something like -60.">gain</a><br/>
    
	   </p>
   
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="gain_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="gain_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="gain_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="gain_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="gain_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="gain_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="gain_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="gain_method_setvalue.html" title="Set the value of this Gain to a given dB value.">setValue ( )</a><br/>
    
    <a href="gain_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="gain_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	Gain is another way of expressing an increase or decrease in the volume of something.
 It is represented in decibels (dB), which is a logorithmic scale. A gain of 0 dB means 
 that you are not changing the volume of the incoming signal at all, positive gain boosts 
 the signal and negative gain decreases it. You can effectively silence 
 the incoming signal by setting the gain to something like -60.
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Construct a Gain UGen with a value of 0 dB, which means 
 it will not change the volume of something patched to it.</em>
Gain()
<em>Construct a Gain with the specific dBvalue. 0 dB is no change 
 to incoming audio, positive values make it louder and negative values 
 make it softer.</em>
Gain(float dBvalue)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">dBvalue</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the amount of gain to apply to the incoming signal</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	
    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  This is an example of how to use a Gain UGen to control the gain of an audio file. 
  Gain is expressed in dB, which is short for decibels, and is way that people 
  often think about the level of digital audio. dB is a change in amplitude 
  relative to whatever the incoming amplitude is, so a gain value of 0 will not change 
  the incoming amplitude at all. Positive gain values increase the amplitude of the 
  incoming signal and negative values decrease it. It's not really possible to completely 
  silence incoming audio with a Gain UGen, but you can set the gain value so low that you 
  effectively silence the audio. 
  &lt;p>
  dB is a logarithmic scale, so while 0 dB will not change the amplitude of incoming 
  audio at all, 6 dB will approximately double the amplitude and -6 dB will approximately halve it.
  &lt;p>
  Move the mouse left and right to change the gain of the looping audio file. 
  All the way left is -6 dB, all the way right is +6 dB.
  &lt;p>
  For more information about Minim and additional features, 
  visit http://code.compartmental.net/minim/
  &lt;p>
  author: Damien Di Fede
*/

import ddf.minim.*;
import ddf.minim.ugens.*;

// declare everything we need to play our file
Minim minim;
FilePlayer filePlayer;
Gain       gain;
AudioOutput out;

// you can use your own file by putting it in the data directory of this sketch
// and changing the value assigned to fileName here.
String fileName = "groove.mp3";

void setup()
{
  // setup the size of the app
  size(640, 240);
  
  // create our Minim object for loading audio
  minim = new Minim(this);
  // this opens the file and puts it in the "play" state.                           
  filePlayer = new FilePlayer( minim.loadFileStream(fileName) );
  // and then we'll tell the recording to loop indefinitely
  filePlayer.loop();
  
  // start the Gain at 0 dB, which means no change in amplitude
  gain = new Gain(0.f);
  
  // get a line out from Minim. It's important that the file is the same audio format 
  // as our output (i.e. same sample rate, number of channels, etc).
  out = minim.getLineOut();
  
  // patch the file player to the output
  filePlayer.patch(gain).patch(out);
                        
}

// draw is run many times
void draw()
{
  // update the gain value. middle of the width will be the original amplitude 
  // of the audio file, far right is twice as loud and far left is half as loud.
  float dB = map(mouseX, 0, width, -6, 6);
  gain.setValue(dB);
  
  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  for( int i = 0; i &lt; out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }  
  
  text("Current Gain is " + dB + " dB.", 10, 20);
}</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>